package cn.rbac.action;

import java.util.List;

import cn.rbac.model.Resource;
import cn.rbac.service.IndexService;

import com.opensymphony.xwork2.ActionSupport;

public class IndexAction extends ActionSupport{
	private List<Resource> resourceList;
	private IndexService indexService=new IndexService();
	private Resource menu;
	private Resource resource;
	private int resourceId;
	
	
	/*
	 * getter & setter
	 */
	
	public int getResourceId() {
		return resourceId;
	}

	public void setResourceId(int resourceId) {
		this.resourceId = resourceId;
	}

	public List<Resource> getResourceList() {
		return resourceList;
	}

	public void setResourceList(List<Resource> resourceList) {
		this.resourceList = resourceList;
	}

	public Resource getMenu() {
		return menu;
	}

	public void setMenu(Resource menu) {
		this.menu = menu;
	}

	public Resource getResource() {
		return resource;
	}

	public void setResource(Resource resource) {
		this.resource = resource;
	}

	@Override
	public String execute(){
		return SUCCESS;
	}
	

	/*
	 * 获取菜单列表
	 */
	public String indexResourceList(){
		System.out.println("resource call");
		resourceList=indexService.getResourceList();
		if(resourceList!=null){
			return SUCCESS;
		}
		return ERROR;
	}
	
	public String indexMenuList(){
		System.out.println("menu call");
		menu=indexService.getMenu();
		if(menu!=null){
			return SUCCESS;
		}
		return ERROR;
	}
	
	/*
	 * 添加资源表单
	 */
	public String indexResourceInput(){
		System.out.println("resource call");
		menu=indexService.getMenu();
		return INPUT;
	}
	
	/*
	 * 添加资源
	 */
	public String indexResourceAdd(){
		System.out.println(resource.getName());
		if(indexService.addResource(resource)){
			return "redirect";
		}
		return ERROR;
	}
	
	/*
	 * 删除资源
	 * 
	 */
	public String indexResourceDel() {
		indexService.delResourceById(resourceId);
		return "redirect";
	}
}
